<?php

namespace App\Http\Middleware;

use Closure;

class Autologin
{
    /**
     * Handle an incoming request.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  \Closure  $next
     * @return mixed
     */
    public function handle($request, Closure $next)
    {
        //如果存在cookie，无论是自动登录的authcookie还是临时登录的usernamecookie，说明当前用户已经登录
        if($request->cookie('authCookie') || $request->cookie('usernameCookie')){
            return $next($request);//可以继续访问
        }
        //否则的话，重定向到登录页面
        return redirect('loginPage');
    }
}
